﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using EFEntity;
using Iservices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.Extensions.Logging;
using Model;
using Newtonsoft.Json;
using Services;

namespace Hr.Controllers
{
    public class HumanResourcesController : Controller
    {
        private readonly Ihuman_registerServices d;
       // private readonly ILogger<HumanResourcesController> logger;
        //private readonly MyDbContext myDbContext;
        public HumanResourcesController(Ihuman_registerServices d)
        {
           // this.myDbContext = myDbContext;
            this.d = d;
           // this.logger = logger;
        }
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult human_register()
        {
            return View();
        }
        public IActionResult query_locate()
        {
            return View();
        }
        /// <summary>
        /// 查询选择一级机构下二级下拉框
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task<ActionResult> GetSecond(string ids)
        {
            List<config_file_second_kind> first = await d.GetSecond(ids);
            return Content(JsonConvert.SerializeObject(first));
        }
        /// <summary>
        /// 查询选择二级机构下三级下拉框
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public async Task<ActionResult> GetThird(string ids)
        {
            List<config_file_third_kind> third = await d.GetThird(ids);
            return Content(JsonConvert.SerializeObject(third));
        }
        /// <summary>
        /// /查询所有一级下拉框
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> GetXiaLaKuang()
        {
            Dictionary<string, object> di = new Dictionary<string, object>();
            List<config_file_first_kind> first = await d.GetFirst();
            List<config_major_kind> majorkind = await d.GetMojarKind();
            List<salary_standard> salary = await d.GetSalary();
            di["first"] = first;
            di["majorkind"] = majorkind;
            di["salary"] = salary;
            return Content(JsonConvert.SerializeObject(di));
        }
        //查询职位分类下职位名称
        public async Task<ActionResult> GetMajor(string ids)
        {
            List<config_major> major = await d.GetMajor(ids);
            return Content(JsonConvert.SerializeObject(major));
        }
        //新增人力资源档案
        public async Task<ActionResult> AddHuman_file(human_file hf)
        {
            hf.check_status = 1;
            hf.human_file_status = 1;
            int num = await d.AddHuman_file(hf);
            return Content(JsonConvert.SerializeObject(num));
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--图片上传
        /// </summary>
        /// <returns></returns>
        public IActionResult register_choose_picture()
        {
            return View();
        }
        /// <summary>
        /// 人力资源档案查询表
        /// </summary>
        /// <returns></returns>
        public IActionResult change_list(string where)
        {
            ViewData["where"] = where;
            return View();
        }
        public IActionResult query_keywords()
        {
            return View();
        }
        /// <summary>
        /// 人力档案查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult query_list(string where)
        {
            ViewData["where"] = where;
            return View();
        }
        /// <summary>
        /// 查询全部复核过信息
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public async Task<ActionResult> GetAllHuman(int currentPage, string where)
        {
            Dictionary<string, object> di = await d.GetHuman_fileOnes(currentPage, where);
            return Content(JsonConvert.SerializeObject(di));
        }
        public IActionResult query_list_information(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        //查询详细信息
        public async Task<ActionResult> GetOneHXinagXi(int id)
        {
            List<human_file> list = await d.GetUOneHuman_file(id);
            return Content(JsonConvert.SerializeObject(list));
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案登记复核
        /// </summary>
        /// <returns></returns>
        public IActionResult check_list()
        {
            return View();
        }
        /// <summary>
        /// 人力资源等级复核表
        /// </summary>
        /// <returns></returns>
        public IActionResult human_check(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        //查询未复核的人力资源档案
        public async Task<ActionResult> GetHuman_fileOne(int id)
        {
            //Dictionary<string, object> di = new Dictionary<string, object>();
            //di = await d.GetHuman_fileOne(currentpage, " check_status = 1 and  human_file_status = 'true' ");
            //return Content(JsonConvert.SerializeObject(di));
            FenYe ye = new FenYe()
            {
                CurrentPage = Convert.ToInt32(id),
                PageSize = 3,
                Where = ""
            };
            Dictionary<string, object> di = new Dictionary<string, object>();
            List<human_file> list = await d.GetHuman_fileOne(ye);
            di["list"] = list;
            di["rows"] = ye.Rows;
            di["pages"] = ye.Pages;
            return Ok(di);

        }
        //复核查询单个
        public async Task<ActionResult> GetUOneHuman_file(int id)
        {
            List<human_file> list = await d.GetUOneHuman_file(id);
            return Content(JsonConvert.SerializeObject(list));
        }
        /// <summary>
        ///  //复核信息
        /// </summary>
        /// <param name="hf"></param>
        /// <returns></returns>
        public async Task<ActionResult> FHHuman_file(human_file hf)
        {
            hf.check_status = 2;
            int num = await d.FHHuman_file(hf);
            return Content(JsonConvert.SerializeObject(num));
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案变更
        /// </summary>
        /// <returns></returns>
        public IActionResult change_locate()
        {
            return View();
        }
        //变更数据
        public async Task<ActionResult> UpdHuman(human_file hf)
        {
            hf.check_status = 1;
            hf.lastly_change_time = DateTime.Now;
          
            int num = await d.UpdHuman_file(hf);
            return Content(JsonConvert.SerializeObject(num));
        }

        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案永久删除
        /// </summary>
        /// <returns></returns>
        public IActionResult delete_keywords()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案删除
        /// </summary>
        /// <returns></returns>
        public IActionResult delete_list(string where)
        {
            ViewData["where"] = where;
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案删除
        /// </summary>
        /// <returns></returns>
        public IActionResult delete_list_information(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        //删除修改状态为不可用（false），恢复状态
        public async Task<ActionResult> DelFalse(human_file hf)
        {
            int num = await d.DelFalse(hf);
            return Content(JsonConvert.SerializeObject(num));
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案删除
        /// </summary>
        /// <returns></returns>
        public IActionResult delete_locate()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案变更查询
        /// </summary>
        /// <returns></returns>
        public IActionResult change_keywords()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案恢复查询
        /// </summary>
        /// <returns></returns>
        public IActionResult recovery_keywords()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案恢复
        /// </summary>
        /// <returns></returns>
        public IActionResult recovery_list(string where)
        {
            ViewData["where"] = where;
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案恢复
        /// </summary>
        /// <returns></returns>
        public IActionResult recovery_list_information(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案恢复
        /// </summary>
        /// <returns></returns>
        public IActionResult recovery_locate()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--附件上传
        /// </summary>
        /// <returns></returns>
        public IActionResult register_choose_attachment()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案永久删除
        /// </summary>
        /// <returns></returns>
        public IActionResult delete_forever_list()
        {
            return View();
        }
        /// <summary>
        /// 人力资源--人力资源档案管理--人力资源档案变更 
        /// </summary>
        /// <returns></returns>
        public IActionResult change_list_information(int id)
        {
            ViewData["id"] = id;
            return View();
        }
        //变更查单个
        public async Task<ActionResult> GetUpdOne(int id)
        {
            Dictionary<string, object> di = new Dictionary<string, object>();
            List<human_file> list = await d.GetUOneHuman_file(id);
            List<salary_standard> salary = await d.GetSalary();
            di["dt"] = list;
            di["salary"] = salary;
            return Content(JsonConvert.SerializeObject(di));
        }
        //返回
        public IActionResult success()
        {
            return View();
        }
        //永久删除
        public IActionResult DelHuman()
        {
            return View();
        }
    }
}
